package com.wp.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: WangPeng
 * @createTime: 2022/12/27 11:26
 * @description:
 * @version: v1.0
 */
@Configuration
public class EsConfig {
    //把方法返回的对象交于spring容器
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        //String hostname, int port, String scheme
        HttpHost httpHost=new HttpHost("localhost",9200,"http");
        //HttpHost... hosts: es可能是一个集群。
        RestClientBuilder restClientBuilder= RestClient.builder(httpHost);
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
        return restHighLevelClient;
    }
}
